package cn.itlaobing.web.service.impl;

import cn.itlaobing.web.entity.SystemUser;
import cn.itlaobing.web.repository.ISystemUserRepository;
import cn.itlaobing.web.service.ISystemUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;

@Service
public class SystemUserServiceImpl implements ISystemUserService{

    @Autowired
    private ISystemUserRepository systemUserRepository;

    @Override
    public SystemUser findByUserAccount(String userAccount) {

        return systemUserRepository.findByUserAccount(userAccount);
    }

    @Override
    public SystemUser findByUserAccountAndUserPass(String userAccount, String userpass) {
        return systemUserRepository.findByUserAccountAndUserPass(userAccount,userpass);
    }

    @Override
    public SystemUser updateHeadImgById(Long id, String headimg) {
        SystemUser user = null;
        Date date = new Date();
        Timestamp time = new Timestamp(date.getTime());
        int i = systemUserRepository.updateHeadImgById(id,headimg,time);
        if(i>0){
            user = systemUserRepository.findOne(id);
        }
        return user;
    }

    @Override
    public SystemUser updatePassById(Long id, String newpass) {
        SystemUser user = null;
        Date date = new Date();
        Timestamp time = new Timestamp(date.getTime());
        int i = systemUserRepository.updatePassById(id,newpass,time);
        if(i>0){
            user = systemUserRepository.findOne(id);
        }
        return user;
    }

    @Override
    public int updateLoginById(Long id, Timestamp time, int islogin) {
        return systemUserRepository.updateLoginById(id,time,islogin);
    }
}
